# -*- coding: utf-8 -*-

from django.shortcuts import render
from datetime import datetime,date

# Create your views here.
from django.http import HttpResponse
from .models import Price, Page, Food, Market

foods = Food.objects.order_by('id')
markets = Market.objects.order_by('id')


def index(request,datestr):
    # datestr = '20150310'
    page_date = datetime.strptime(datestr, '%Y%m%d').date()
    purchase_date = Page.objects.get(page_date=page_date)
    prices = Price.objects.filter(page=purchase_date)

    context = {'purchase_date_price': prices,
               'purchase_date': purchase_date,
               'markets': markets
               }

    return render(request, 'food/index.html', context)
